package pt.um.jspecput.lib.writer;

import static pt.um.jspecput.util.Constants.*;

import java.util.ArrayList;

/**
 * The Class Class.
 */
public class Class {

    /** The package name. */
    private String packageName;

    /** The import declarations. */
    private ArrayList<String> importDeclarations;

    /** The class name. */
    private String className;

    /**
     * Instantiates a new class.
     */
    public Class() {
    }

    /**
     * Instantiates a new class.
     * 
     * @param className
     *            the class name
     */
    public Class(String className) {
        this.className = className;
    }

    /**
     * Gets the package name.
     * 
     * @return the package name
     */
    public String getPackageName() {
        return packageName;
    }

    /**
     * Sets the package name.
     * 
     * @param packageName
     *            the new package name
     */
    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    /**
     * Gets the import declarations.
     * 
     * @return the import declarations
     */
    public ArrayList<String> getImportDeclarations() {
        return importDeclarations;
    }

    /**
     * Sets the import declarations.
     * 
     * @param importDeclarations
     *            the new import declarations
     */
    public void setImportDeclarations(ArrayList<String> importDeclarations) {
        this.importDeclarations = importDeclarations;
    }

    /**
     * Gets the class name.
     * 
     * @return the class name
     */
    public String getClassName() {
        return className;
    }

    /**
     * Sets the class name.
     * 
     * @param className
     *            the new class name
     */
    public void setClassName(String className) {
        this.className = className;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        final int prime = PRIME;
        int result = 1;
        result = prime * result
                + ((className == null) ? 0 : className.hashCode());
        result = prime
                * result
                + ((importDeclarations == null) ? 0 : importDeclarations
                        .hashCode());
        result = prime * result
                + ((packageName == null) ? 0 : packageName.hashCode());
        return result;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Class other = (Class) obj;
        boolean areEquals = true;
        areEquals &= (className == null ? className == other.getClassName()
                : className.equals(other.getClassName()));
        areEquals &= (importDeclarations == null ? importDeclarations == other
                .getImportDeclarations() : importDeclarations.equals(other
                .getImportDeclarations()));
        areEquals &= (packageName == null ? packageName == other
                .getPackageName() : packageName.equals(other.getPackageName()));
        return areEquals;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "Class: " + packageName + DOT + className;
    }
}
